const mongoose=require('mongoose');
const moment=require('moment');
moment.locale('zh-cn');

const CommentSchema = new mongoose.Schema({
    post:{
        type:mongoose.Schema.ObjectId,
        ref:'Post',
        required:true
    },
    author:{
        type:mongoose.Schema.ObjectId,
        ref:'User',
        required:true,
    },
    content:{
        type:String,
        required:true
    },
    time:{
        type:Date,
        required:true
    },
    //赞
    ups:[{
        type:mongoose.Schema.ObjectId,
        ref:'User'
    }],
    //@user
    atUser:{
        _id:{
            type:mongoose.Schema.ObjectId,
            ref:'User'
        },
        name:String
    }
});

CommentSchema.virtual('ago').get(function(){
    return moment(this.time).fromNow();
});

module.exports=mongoose.model('Comment',CommentSchema);